package com.itcast.activiti.config;

import com.itcast.msas.sdk.base.OpenApiFactory;
import com.itcast.msas.sdk.base.auth.MsasAuth;
import com.itcast.msas.sdk.msg.api.AppchatApi;
import com.itcast.msas.sdk.msg.api.WechatMsgApi;
import com.itcast.msas.sdk.usr.api.MsasUserApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
public class MsasClientConfig {


    private final MsasConfigProperties msasConfigProperties;

    public MsasClientConfig(MsasConfigProperties msasConfigProperties) {
        this.msasConfigProperties = msasConfigProperties;
    }

    @Bean
    public MsasAuth msasAuth() {
        MsasAuth msasAuth = new MsasAuth.MsasAuthBuilder()
                .setClientId(msasConfigProperties.getClientId())
                .setPrivateKey(msasConfigProperties.getPrivateKey())
                .setBaseUrl(msasConfigProperties.getBaseUrl())
                .build();
        return msasAuth;
    }

    @Bean
    @DependsOn("msasAuth")
    public WechatMsgApi wechatMsgApi() {
        return OpenApiFactory.getOpenApi(WechatMsgApi.class);
    }

    @Bean
    @DependsOn("msasAuth")
    public AppchatApi appchatApi() {
        return OpenApiFactory.getOpenApi(AppchatApi.class);
    }

    @Bean
    @DependsOn("msasAuth")
    public MsasUserApi msasUserApi() {
        return OpenApiFactory.getOpenApi(MsasUserApi.class);
    }
}
